<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use App\Models\Fang;
use App\Models\Node;
use Illuminate\Http\Request;

class IndexController extends BaseController
{
    /**
     * 后台首页
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     */
    public function index()
    {

        //获取session里的保存用户权限
        $nodes = session('admin_auths');
        $node = Node::where('is_menu','1');
        //判断用户是否超级管理员
        if($nodes !== true){
            //取出权限的下标
            $node_id = array_keys($nodes);
            //搜索当前用户的权限
            $nodeData = $node->whereIn('id',$node_id)->get();
        }else{
            //超级管理员拥有所有权限
            $nodeData = $node->get();
        }

        $nodeData = $this->sonlevel($nodeData);

        return view('admin/index/index',compact('nodeData'));
    }


    /**
     * 我的桌面
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     */
    public function welcome(){

        $lease = Fang::where('fang_status',1)->count();
        $noLease = Fang::where('fang_status',0)->count();
        return view('admin/index/welcome',compact('lease','noLease'));
    }

    /**
     *无权限页面
     */
    public function error()
    {
        return view('admin.index.error');
    }
}
